use crate::core::{common::Sex, student::Student, token_manage::Claims};
use actix_web::{Responder, Result, get, web};

#[get("/students")]
pub async fn students(user: Claims, query: web::Query<StudentQuery>) -> Result<impl Responder> {
    println!("{:?}", user);
    let students = Student::list_all_student(query.name.clone(), query.page_index, query.page_size)
        .await
        .map_err(|e| actix_web::error::ErrorInternalServerError(e))?;
    Ok(web::Json(students))
}

struct StudentVM {
    name: String,
    grade: u8,
    sex: Sex,
    add_time: time::Date,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct StudentQuery {
    name: Option<String>,
    page_index: u8,
    page_size: u8,
}
